<?php slot('sub', $sub); ?>
<?php slot('data', $data); ?>
<?php slot('menu', $menu); ?>
<?php slot('user', $user); ?>
<?php  use_javascript('mainFunctions.js');?>
<?php  use_javascript('script.js');?>
<?php  use_javascript('server.js');?>
<div class="center">
    <div id="center_conteiner" class="clearfix">
        <div class="center_sub_conteiner">
            <!--left container-->
            <div class="left_block_container">

                <div class="left_block">
                    <div class="header_left_block"><span>For Business</span></div>
                    <div class="left_block_row">
                        <div>
                            <a href="<?php echo url_for('hotels', array('page' => 1, 'sort' => 'price')) ?>">
                                <img src="../images/icoHotels.png"/>
                                <p>Hotels</p>
                            </a>
                        </div>
                        <div>
                            <img src="../images/icoAppartments.png"/>
                            <p>Apartments</p>
                        </div>
                        <div>
                            <img src="../images/icoAirTickets.png"/>
                            <p>Airtickets</p>
                        </div>
                        <div>
                            <img src="../images/icoTourPack.png"/>
                            <p>Tour Packages</p>
                        </div>
                        <div>
                            <img src="../images/icoTourPackPers.png"/>
                            <p>Personal Tour</p>
                        </div>
                    </div>
                    <div class="left_block_row">
                        <div>
                            <img src="../images/icoTransfer.png"/>
                            <p>Transfers</p>
                        </div>
                        <div>
                            <img src="../images/icoExcursion.png"/>
                            <p>Excursion</p>
                        </div>
                        <div>
                            <img src="../images/icoCar.png"/>
                            <p>Car Rent</p>
                        </div>
                        <div>
                            <img src="../images/icoHow.png"/>
                            <p>How it Work</p>
                        </div>
                        <div>
                            <img src="../images/icoWeb.png"/>
                            <p>Web Site</p>
                        </div>
                    </div>
                </div>

                <div class="left_block">
                    <div class="header_left_block"><span>Find our nearest agent for you</span></div>
                    <div class="locator_block">
                        <div class="locator_img_block">
                            <img src="../images/earth.png">
                        </div>
                        <div class="locator_info_block">
                            <!--div class="locator_info_block_title"></div-->
                            <div class="locator_info_block_location">
                                <img src="../images/locator_loader.gif"/>
                            </div>
                            <div class="locator_info_block_agents">
                                <ul class="lida_container"></ul>
                            </div>
                            <div class="lida_container_more" onclick="moreAgetns()">more...</div>
                        </div>
                    </div>
                </div>

            </div>
            <!-- right block -->
            <div class="right_block_container">

                <div class="right_block">
                    <div class="header_right_block"><span>Rate</span></div>
                    <div class="text_right_block"><?php echo $day ?></div>
                    <div class="text_right_block">USD 3.59 | EUR 4.73 | RUB 3.95</div>
                </div>

                <div class="right_block">
                    <div class="header_right_block"><span>For Tourists</span></div>
                    <div class="text_center_right_block">All Israel Hotel, airticets, own tours four you</div>
                    <div class="text_center_right_block">Book it now</div>
                    <div class="footer_right_block">We are glad to help you on your vacation</div>
                </div>

                <div class="right_block">
                    <div class="header_right_block"><span>Support</span></div>
                    <div class="text_right_block">Phone: +972 545 337659</div>
                    <div class="text_right_block">Email: <span>troli@traivis.co.il</span></div>
                </div>

                <div class="right_block">
                    <div class="header_right_block"><span>Online now</span></div>
                    <div class="image_row_right_block">
                        <ul>
                            <li><img src="../images/icoOrders.png"/></li>
                            <li><span class="col_one"><?php echo $orders ?></span></li>
                            <li><span class="col_two">Orders</span></li>
                        </ul>
                    </div>
                    <div class="image_row_right_block">
                        <ul>
                            <li><img src="../images/icoHotelss.png"/></li>
                            <li><span class="col_one"><?php echo $hotels ?></span></li>
                            <li><span class="col_two">Hotels</span></li>
                        </ul>
                    </div>
                    <div class="image_row_right_block">
                        <ul>
                            <li><img src="../images/icoRooms.png"/></li>
                            <li><span class="col_one"><?php echo $rooms ?></span></li>
                            <li><span class="col_two">Available rooms</span></li>
                        </ul>
                    </div>
                    <div class="image_row_right_block">
                        <ul>
                            <li><img src="../images/icoAgents.png"/></li>
                            <li><span class="col_one"><?php echo $agents ?></span></li>
                            <li><span class="col_two">Agents</span></li>
                        </ul>
                    </div>

                    <div class="empty_block"></div>
                </div>

            </div>
        </div>
    </div>
</div>

<div class="popup_reset">
    <div class="popup_reset_header">
        <div class="popup_reset_title">
            <span>Reset your password</span>
        </div>
        <div class="popup_reset_close">
            <img src="../images/icoCancel.png"/>
        </div>
    </div>

    <input type="text" id="reset_username" placeholder="Enter your username"/>
    <input type="button" id="button_reset_username" value="Reset"/>
</div>

<div class="loader">
    <img src="../images/loader.gif"/>
</div>

<div id="blackout"></div>

<script>
    var latitude = null;
    var longitude = null;

    window.onload = function() {
       get_lat_lng();
        /*if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(handleGetCurrentPosition, onError);
        }*/
    };
    function get_lat_lng()
    {
        var ip='<?php echo $_SERVER['REMOTE_ADDR'];?>';
        $.ajax({
        url: "https://freegeoip.net/json/"+ip,
        cache: false
        })
        .done(function( data ) {
            latitude=data.latitude;
            longitude=data.longitude;
             console.log(latitude, longitude);
            getAgents(latitude, longitude, 2);
            
        }).fail(function() {
           onError();
        });
    }
    function handleGetCurrentPosition(location) {
        latitude = location.coords.latitude;
        longitude = location.coords.longitude;

        console.log(latitude, longitude);

        getAgents(latitude, longitude, 2);
    }

    function onError() {
        latitude = 32.07662;
        longitude = 34.787466;

        getAgents(latitude, longitude, 2);
    }

    function getAgents(latitude, longitude, limit) {
       
        $.ajax({
            type: 'POST',
            data: {
                latitude: latitude,
                longitude: longitude,
                limit: limit
            },
            url: urlBackend + 'locator',
            success: function(msg) {
                var json = $.parseJSON(msg);

                $(json).each(function(i, v) {
                    console.log(v.possition);
                    parseAgents(v.agents, v.possition);
                });
            }
        });
    }

    function parseAgents(data, possition) {
        
        $('.locator_info_block_location img').remove();
        $('.lida_container li').remove();
        var ul = $('.lida_container');

        $('.locator_info_block_location').html('You Location: '+possition);
       
        $.each(data, function(i, v) {

            var newLi = $('<li />');
            var newUl = $('<ul />').addClass('lidac_inner').attr({'agent_id': v.id});
            var lida_name = $('<li />').addClass('lida_name').html(v.title).css({'cursor': 'default', 'text-decoration': 'underline'});
            var lida_ratio = $('<li />').addClass('lida_ratio').html(v.reputation).attr({'title': 'reputation ' + v.reputation + '/5'});
            var lida_separ = $('<li />').addClass('lida_separ').html('|');
            var lida_users = $('<li />').addClass('lida_users').html(v.orders).attr({'title': 'agent orders'});
            var lida_container_separ = $('<li />').addClass('lida_container_separ');

            if (parseFloat(v.reputation) >= 4) {
                $(lida_ratio).css({'color': '#19a44b', 'cursor': 'default'});
            } else if (parseFloat(v.reputation) < 4 && parseFloat(v.reputation) >= 2.5) {
                $(lida_ratio).css({'color': '#ffc000', 'cursor': 'default'});
            } else {
                $(lida_ratio).css({'color': '#b02358', 'cursor': 'default'});
            }

            $(lida_users).css({'color': '#20aedc', 'cursor': 'default'});
            $(newUl).click(function() {
                console.log($(this).attr('agent_id'));
                var agent_id = $(this).attr('agent_id');
                window.location.assign(urlBackend + 'agentpage/agent/' + agent_id);
            });
            (newLi).append((newUl).append(lida_name).append(lida_ratio).append(lida_separ).append(lida_users));
            (ul).append(newLi).append(lida_container_separ);
        });
    }

    function moreAgetns() {
        window.location.assign(urlBackend + 'agents/lt/' + latitude + '/ln/' + longitude);
    }
</script>

<!--<li>
    <ul class="lidac_inner">
        <li class="lida_name">Fortuna</li>
        <li class="lida_ratio">5</li>
        <li class="lida_separ">|</li>
        <li class="lida_users">120</li>
    </ul>
</li>
<li class="lida_container_separ">*</li>-->